package com.rgp.servicepassengeruser.service.impl;

import com.rgp.internalcommon.common.PassengerInfoConstant;
import com.rgp.internalcommon.dto.UserInfoDto;
import com.rgp.internalcommon.utils.NameGenerateUtils;
import com.rgp.servicepassengeruser.mapper.PassengerUserMapper;
import com.rgp.servicepassengeruser.pojo.PassengerUser;
import com.rgp.servicepassengeruser.service.PassengerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-12 23:00
 */
@Service
public class PassengerUserServiceImpl implements PassengerUserService {

    @Autowired
    private PassengerUserMapper passengerUserMapper;

    @Override
    public List<PassengerUser> getPassengerByPhoneNumber(String passengerPhone) {

        Map<String,Object> map = new HashMap<>();
        map.put("passenger_phone",passengerPhone);
        //根据手机号查询乘客信息
        List<PassengerUser> passengerUsers = passengerUserMapper.selectByMap(map);
        return passengerUsers;
    }

    @Override
    public Integer registPassenger(UserInfoDto userInfoDto) {

        PassengerUser passengerUser = new PassengerUser();
        if (userInfoDto.getUserName() != null){
            passengerUser.setPassengerName(userInfoDto.getUserName());
        }else{
            passengerUser.setPassengerName(NameGenerateUtils.getRandomName());
        }
        passengerUser.setPassengerPhone(userInfoDto.getUserPhone());
        if (userInfoDto.getPassengerGender()!= null){
            passengerUser.setPassengerGender(userInfoDto.getPassengerGender());
        }else{
            passengerUser.setPassengerGender(PassengerInfoConstant.PASSENGER_GENDER_DEFAULT);
        }

        return passengerUserMapper.insert(passengerUser);
    }
}